<?php

/*
* Plugin Name: Gforms Iranian Mobile Number
* Plugin URI: https://notabug.org/wp/gf-iran-mobile
* Description: Validate phone numbers be like 09133917225
* Author: Saeb Molaee
* Version: 1.0
* Author URI: https://saeb.sbs/
* Text Domain: gf-iran-mobile
* Domain Path: /languages
*/


if (!class_exists('SAEB_GF_FIELD_TEXT_IRAN_MOBILE') && class_exists('GF_Field_Text')) {
	class SAEB_GF_FIELD_TEXT_IRAN_MOBILE extends GF_Field_Text
	{
		public $type = 'IranianMobileNumber';

		public function get_form_editor_field_title()
		{
			return __('Iranian Mobile Number','gf-iran-mobile');
		}
		public function validate($value, $form)
		{
			parent::validate($value, $form);
			$validate = mb_ereg("^09\d{9}$", $value);

			if (!$validate) {
				$this->failed_validation = true;
				$this->fail_validation = true;
				$old_message = $this->validation_message;
				$message = __('Phone number must start with 09','gf-iran-mobile');
				$this->validation_message = "${old_message} ${message}";
			}
		}
	}
	GF_Fields::register(new SAEB_GF_FIELD_TEXT_IRAN_MOBILE());


	add_action( 'init', 'wpdocs_load_textdomain1' );
 
function wpdocs_load_textdomain1() {
    load_plugin_textdomain( 'gf-iran-mobile', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 
}
}


